package com.facebook.imagepipeline.producers;

import com.facebook.common.internal.ImmutableMap;
import com.facebook.common.internal.Preconditions;
import com.facebook.common.internal.VisibleForTesting;
import com.facebook.common.util.TriState;
import com.facebook.imageformat.ImageFormat;
import com.facebook.imagepipeline.common.ResizeOptions;
import com.facebook.imagepipeline.image.EncodedImage;
import com.facebook.imagepipeline.memory.PooledByteBufferFactory;
import com.facebook.imagepipeline.request.ImageRequest;
import java.util.Map;
import java.util.concurrent.Executor;
import javax.annotation.Nullable;

public class ResizeAndRotateProducer
  implements Producer<EncodedImage>
{

  @VisibleForTesting
  static final int DEFAULT_JPEG_QUALITY = 85;
  private static final String FRACTION_KEY = "Fraction";

  @VisibleForTesting
  static final int MAX_JPEG_SCALE_NUMERATOR = 8;

  @VisibleForTesting
  static final int MIN_TRANSFORM_INTERVAL_MS = 100;
  private static final String ORIGINAL_SIZE_KEY = "Original size";
  private static final String PRODUCER_NAME = "ResizeAndRotateProducer";
  private static final String REQUESTED_SIZE_KEY = "Requested size";
  private static final float ROUNDUP_FRACTION = 0.6666667F;
  private final Executor mExecutor;
  private final Producer<EncodedImage> mInputProducer;
  private final PooledByteBufferFactory mPooledByteBufferFactory;

  public ResizeAndRotateProducer(Executor paramExecutor, PooledByteBufferFactory paramPooledByteBufferFactory, Producer<EncodedImage> paramProducer)
  {
    this.mExecutor = ((Executor)Preconditions.checkNotNull(paramExecutor));
    this.mPooledByteBufferFactory = ((PooledByteBufferFactory)Preconditions.checkNotNull(paramPooledByteBufferFactory));
    this.mInputProducer = ((Producer)Preconditions.checkNotNull(paramProducer));
  }

  @VisibleForTesting
  static float determineResizeRatio(ResizeOptions paramResizeOptions, int paramInt1, int paramInt2)
  {
    float f;
    if (paramResizeOptions == null)
      f = 1.0F;
    do
    {
      return f;
      f = Math.max(paramResizeOptions.width / paramInt1, paramResizeOptions.height / paramInt2);
      if (f * paramInt1 > 2048.0F)
        f = 2048.0F / paramInt1;
    }
    while (f * paramInt2 <= 2048.0F);
    return 2048.0F / paramInt2;
  }

  private static int getRotationAngle(ImageRequest paramImageRequest, EncodedImage paramEncodedImage)
  {
    if (!paramImageRequest.getAutoRotateEnabled())
      return 0;
    int i = paramEncodedImage.getRotationAngle();
    boolean bool;
    if ((i != 0) && (i != 90) && (i != 180))
    {
      bool = false;
      if (i != 270);
    }
    else
    {
      bool = true;
    }
    Preconditions.checkArgument(bool);
    return i;
  }

  private static int getScaleNumerator(ImageRequest paramImageRequest, EncodedImage paramEncodedImage)
  {
    ResizeOptions localResizeOptions = paramImageRequest.getResizeOptions();
    int n;
    if (localResizeOptions == null)
      n = 8;
    label49: label89: label98: label107: 
    do
    {
      return n;
      int i = getRotationAngle(paramImageRequest, paramEncodedImage);
      int j;
      int k;
      if ((i == 90) || (i == 270))
      {
        j = 1;
        if (j == 0)
          break label89;
        k = paramEncodedImage.getHeight();
        if (j == 0)
          break label98;
      }
      for (int m = paramEncodedImage.getWidth(); ; m = paramEncodedImage.getHeight())
      {
        n = roundNumerator(determineResizeRatio(localResizeOptions, k, m));
        if (n <= 8)
          break label107;
        return 8;
        j = 0;
        break;
        k = paramEncodedImage.getWidth();
        break label49;
      }
    }
    while (n >= 1);
    return 1;
  }

  @VisibleForTesting
  static int roundNumerator(float paramFloat)
  {
    return (int)(0.6666667F + 8.0F * paramFloat);
  }

  private static boolean shouldResize(int paramInt)
  {
    return paramInt < 8;
  }

  private static TriState shouldTransform(ImageRequest paramImageRequest, EncodedImage paramEncodedImage)
  {
    if ((paramEncodedImage == null) || (paramEncodedImage.getImageFormat() == ImageFormat.UNKNOWN))
      return TriState.UNSET;
    if (paramEncodedImage.getImageFormat() != ImageFormat.JPEG)
      return TriState.NO;
    if ((getRotationAngle(paramImageRequest, paramEncodedImage) != 0) || (shouldResize(getScaleNumerator(paramImageRequest, paramEncodedImage))));
    for (boolean bool = true; ; bool = false)
      return TriState.valueOf(bool);
  }

  public void produceResults(Consumer<EncodedImage> paramConsumer, ProducerContext paramProducerContext)
  {
    this.mInputProducer.produceResults(new TransformingConsumer(paramConsumer, paramProducerContext), paramProducerContext);
  }

  private class TransformingConsumer extends DelegatingConsumer<EncodedImage, EncodedImage>
  {
    private boolean mIsCancelled = false;
    private final JobScheduler mJobScheduler;
    private final ProducerContext mProducerContext;

    public TransformingConsumer(ProducerContext arg2)
    {
      super();
      Object localObject;
      this.mProducerContext = localObject;
      JobScheduler.JobRunnable local1 = new JobScheduler.JobRunnable()
      {
        public void run(EncodedImage paramAnonymousEncodedImage, boolean paramAnonymousBoolean)
        {
          ResizeAndRotateProducer.TransformingConsumer.this.doTransform(paramAnonymousEncodedImage, paramAnonymousBoolean);
        }
      };
      this.mJobScheduler = new JobScheduler(ResizeAndRotateProducer.this.mExecutor, local1, 100);
      this.mProducerContext.addCallbacks(new BaseProducerContextCallbacks()
      {
        public void onCancellationRequested()
        {
          ResizeAndRotateProducer.TransformingConsumer.this.mJobScheduler.clearJob();
          ResizeAndRotateProducer.TransformingConsumer.access$402(ResizeAndRotateProducer.TransformingConsumer.this, true);
          localConsumer.onCancellation();
        }

        public void onIsIntermediateResultExpectedChanged()
        {
          if (ResizeAndRotateProducer.TransformingConsumer.this.mProducerContext.isIntermediateResultExpected())
            ResizeAndRotateProducer.TransformingConsumer.this.mJobScheduler.scheduleJob();
        }
      });
    }

    // ERROR //
    private void doTransform(EncodedImage paramEncodedImage, boolean paramBoolean)
    {
      // Byte code:
      //   0: aload_0
      //   1: getfield 24	com/facebook/imagepipeline/producers/ResizeAndRotateProducer$TransformingConsumer:mProducerContext	Lcom/facebook/imagepipeline/producers/ProducerContext;
      //   4: invokeinterface 71 1 0
      //   9: aload_0
      //   10: getfield 24	com/facebook/imagepipeline/producers/ResizeAndRotateProducer$TransformingConsumer:mProducerContext	Lcom/facebook/imagepipeline/producers/ProducerContext;
      //   13: invokeinterface 75 1 0
      //   18: ldc 77
      //   20: invokeinterface 83 3 0
      //   25: aload_0
      //   26: getfield 24	com/facebook/imagepipeline/producers/ResizeAndRotateProducer$TransformingConsumer:mProducerContext	Lcom/facebook/imagepipeline/producers/ProducerContext;
      //   29: invokeinterface 87 1 0
      //   34: astore_3
      //   35: aload_0
      //   36: getfield 17	com/facebook/imagepipeline/producers/ResizeAndRotateProducer$TransformingConsumer:this$0	Lcom/facebook/imagepipeline/producers/ResizeAndRotateProducer;
      //   39: invokestatic 91	com/facebook/imagepipeline/producers/ResizeAndRotateProducer:access$600	(Lcom/facebook/imagepipeline/producers/ResizeAndRotateProducer;)Lcom/facebook/imagepipeline/memory/PooledByteBufferFactory;
      //   42: invokeinterface 97 1 0
      //   47: astore 4
      //   49: aconst_null
      //   50: astore 5
      //   52: aconst_null
      //   53: astore 6
      //   55: aload_3
      //   56: aload_1
      //   57: invokestatic 101	com/facebook/imagepipeline/producers/ResizeAndRotateProducer:access$700	(Lcom/facebook/imagepipeline/request/ImageRequest;Lcom/facebook/imagepipeline/image/EncodedImage;)I
      //   60: istore 9
      //   62: aload_0
      //   63: aload_1
      //   64: aload_3
      //   65: iload 9
      //   67: invokespecial 105	com/facebook/imagepipeline/producers/ResizeAndRotateProducer$TransformingConsumer:getExtraMap	(Lcom/facebook/imagepipeline/image/EncodedImage;Lcom/facebook/imagepipeline/request/ImageRequest;I)Ljava/util/Map;
      //   70: astore 5
      //   72: aload_1
      //   73: invokevirtual 111	com/facebook/imagepipeline/image/EncodedImage:getInputStream	()Ljava/io/InputStream;
      //   76: astore 6
      //   78: aload 6
      //   80: aload 4
      //   82: aload_3
      //   83: aload_1
      //   84: invokestatic 114	com/facebook/imagepipeline/producers/ResizeAndRotateProducer:access$800	(Lcom/facebook/imagepipeline/request/ImageRequest;Lcom/facebook/imagepipeline/image/EncodedImage;)I
      //   87: iload 9
      //   89: bipush 85
      //   91: invokestatic 120	com/facebook/imagepipeline/nativecode/JpegTranscoder:transcodeJpeg	(Ljava/io/InputStream;Ljava/io/OutputStream;III)V
      //   94: aload 4
      //   96: invokevirtual 126	com/facebook/imagepipeline/memory/PooledByteBufferOutputStream:toByteBuffer	()Lcom/facebook/imagepipeline/memory/PooledByteBuffer;
      //   99: invokestatic 132	com/facebook/common/references/CloseableReference:of	(Ljava/io/Closeable;)Lcom/facebook/common/references/CloseableReference;
      //   102: astore 10
      //   104: new 107	com/facebook/imagepipeline/image/EncodedImage
      //   107: dup
      //   108: aload 10
      //   110: invokespecial 135	com/facebook/imagepipeline/image/EncodedImage:<init>	(Lcom/facebook/common/references/CloseableReference;)V
      //   113: astore 11
      //   115: aload 11
      //   117: getstatic 141	com/facebook/imageformat/ImageFormat:JPEG	Lcom/facebook/imageformat/ImageFormat;
      //   120: invokevirtual 145	com/facebook/imagepipeline/image/EncodedImage:setImageFormat	(Lcom/facebook/imageformat/ImageFormat;)V
      //   123: aload 11
      //   125: invokevirtual 149	com/facebook/imagepipeline/image/EncodedImage:parseMetaData	()V
      //   128: aload_0
      //   129: getfield 24	com/facebook/imagepipeline/producers/ResizeAndRotateProducer$TransformingConsumer:mProducerContext	Lcom/facebook/imagepipeline/producers/ProducerContext;
      //   132: invokeinterface 71 1 0
      //   137: aload_0
      //   138: getfield 24	com/facebook/imagepipeline/producers/ResizeAndRotateProducer$TransformingConsumer:mProducerContext	Lcom/facebook/imagepipeline/producers/ProducerContext;
      //   141: invokeinterface 75 1 0
      //   146: ldc 77
      //   148: aload 5
      //   150: invokeinterface 153 4 0
      //   155: aload_0
      //   156: invokevirtual 157	com/facebook/imagepipeline/producers/ResizeAndRotateProducer$TransformingConsumer:getConsumer	()Lcom/facebook/imagepipeline/producers/Consumer;
      //   159: aload 11
      //   161: iload_2
      //   162: invokeinterface 163 3 0
      //   167: aload 11
      //   169: invokestatic 167	com/facebook/imagepipeline/image/EncodedImage:closeSafely	(Lcom/facebook/imagepipeline/image/EncodedImage;)V
      //   172: aload 10
      //   174: invokestatic 169	com/facebook/common/references/CloseableReference:closeSafely	(Lcom/facebook/common/references/CloseableReference;)V
      //   177: aload 6
      //   179: invokestatic 175	com/facebook/common/internal/Closeables:closeQuietly	(Ljava/io/InputStream;)V
      //   182: aload 4
      //   184: invokevirtual 178	com/facebook/imagepipeline/memory/PooledByteBufferOutputStream:close	()V
      //   187: return
      //   188: astore 13
      //   190: aload 11
      //   192: invokestatic 167	com/facebook/imagepipeline/image/EncodedImage:closeSafely	(Lcom/facebook/imagepipeline/image/EncodedImage;)V
      //   195: aload 13
      //   197: athrow
      //   198: astore 12
      //   200: aload 10
      //   202: invokestatic 169	com/facebook/common/references/CloseableReference:closeSafely	(Lcom/facebook/common/references/CloseableReference;)V
      //   205: aload 12
      //   207: athrow
      //   208: astore 8
      //   210: aload_0
      //   211: getfield 24	com/facebook/imagepipeline/producers/ResizeAndRotateProducer$TransformingConsumer:mProducerContext	Lcom/facebook/imagepipeline/producers/ProducerContext;
      //   214: invokeinterface 71 1 0
      //   219: aload_0
      //   220: getfield 24	com/facebook/imagepipeline/producers/ResizeAndRotateProducer$TransformingConsumer:mProducerContext	Lcom/facebook/imagepipeline/producers/ProducerContext;
      //   223: invokeinterface 75 1 0
      //   228: ldc 77
      //   230: aload 8
      //   232: aload 5
      //   234: invokeinterface 182 5 0
      //   239: aload_0
      //   240: invokevirtual 157	com/facebook/imagepipeline/producers/ResizeAndRotateProducer$TransformingConsumer:getConsumer	()Lcom/facebook/imagepipeline/producers/Consumer;
      //   243: aload 8
      //   245: invokeinterface 186 2 0
      //   250: aload 6
      //   252: invokestatic 175	com/facebook/common/internal/Closeables:closeQuietly	(Ljava/io/InputStream;)V
      //   255: aload 4
      //   257: invokevirtual 178	com/facebook/imagepipeline/memory/PooledByteBufferOutputStream:close	()V
      //   260: return
      //   261: astore 7
      //   263: aload 6
      //   265: invokestatic 175	com/facebook/common/internal/Closeables:closeQuietly	(Ljava/io/InputStream;)V
      //   268: aload 4
      //   270: invokevirtual 178	com/facebook/imagepipeline/memory/PooledByteBufferOutputStream:close	()V
      //   273: aload 7
      //   275: athrow
      //   276: astore 7
      //   278: goto -15 -> 263
      //   281: astore 8
      //   283: goto -73 -> 210
      //   286: astore 12
      //   288: goto -88 -> 200
      //
      // Exception table:
      //   from	to	target	type
      //   123	167	188	finally
      //   115	123	198	finally
      //   167	172	198	finally
      //   190	198	198	finally
      //   55	104	208	java/lang/Exception
      //   200	208	208	java/lang/Exception
      //   55	104	261	finally
      //   200	208	261	finally
      //   210	250	261	finally
      //   172	177	276	finally
      //   172	177	281	java/lang/Exception
      //   104	115	286	finally
    }

    private Map<String, String> getExtraMap(EncodedImage paramEncodedImage, ImageRequest paramImageRequest, int paramInt)
    {
      if (!this.mProducerContext.getListener().requiresExtraMap(this.mProducerContext.getId()))
        return null;
      String str1 = paramEncodedImage.getWidth() + "x" + paramEncodedImage.getHeight();
      String str2;
      if (paramImageRequest.getResizeOptions() != null)
      {
        str2 = paramImageRequest.getResizeOptions().width + "x" + paramImageRequest.getResizeOptions().height;
        if (paramInt <= 0)
          break label163;
      }
      label163: for (String str3 = paramInt + "/8"; ; str3 = "")
      {
        return ImmutableMap.of("Original size", str1, "Requested size", str2, "Fraction", str3, "queueTime", String.valueOf(this.mJobScheduler.getQueuedTime()));
        str2 = "Unspecified";
        break;
      }
    }

    protected void onNewResultImpl(@Nullable EncodedImage paramEncodedImage, boolean paramBoolean)
    {
      if (this.mIsCancelled);
      do
      {
        TriState localTriState;
        do
        {
          do
          {
            return;
            if (paramEncodedImage != null)
              break;
          }
          while (!paramBoolean);
          getConsumer().onNewResult(null, true);
          return;
          localTriState = ResizeAndRotateProducer.shouldTransform(this.mProducerContext.getImageRequest(), paramEncodedImage);
        }
        while ((!paramBoolean) && (localTriState == TriState.UNSET));
        if (localTriState != TriState.YES)
        {
          getConsumer().onNewResult(paramEncodedImage, paramBoolean);
          return;
        }
      }
      while ((!this.mJobScheduler.updateJob(paramEncodedImage, paramBoolean)) || ((!paramBoolean) && (!this.mProducerContext.isIntermediateResultExpected())));
      this.mJobScheduler.scheduleJob();
    }
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.facebook.imagepipeline.producers.ResizeAndRotateProducer
 * JD-Core Version:    0.6.2
 */